package org.oy.sealogger.ui;

import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.geom.Ellipse2D;
import java.util.Observable;
import java.util.Observer;
import java.util.Random;

import org.oy.sealogger.parser.CurrentState;
import org.oy.sealogger.parser.RMCSentence;

public class GWaypoint {

	private String longitude = "";
	private String latitude = "";
	
	private LoggerGraphics lg = null;

	private Random rand = new Random();
	
	public GWaypoint(LoggerGraphics l) {
		this.lg = l;
	}
	
	
	public void draw(Graphics g) {
		Graphics2D g2 = (Graphics2D)g;
		
		g2.setPaint(Color.ORANGE);
		g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.8f));
		g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);

		double x = rand.nextDouble() * 200 + 20; 
		double y = rand.nextDouble() * 200 + 20;
		
		Ellipse2D ellipse = new Ellipse2D.Double( x,y, 10,10);
		g2.fill(ellipse);
	}

	public void setLocation(String lon, String lat) {
		this.latitude = lat;
		this.longitude = lon;
	}
	
	public void update(Observable state, Object arg) {
		RMCSentence rmc = ((CurrentState)state).getGPSLocation();

		String lon = rmc.getLongitude();
		String lat = rmc.getLatitude();
		this.setLocation(lon, lat);
		
		//this.lg.repaint();	
	}
	
}
